/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.iecg.controller.screen;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iecg.api.entity.IecgScreenDevice;
import com.iecg.service.IecgScreenDeviceService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 设备中心
 *
 * @author pigx code generator
 * @date 2019-09-30 10:06:34
 */
@RestController
@AllArgsConstructor
@RequestMapping("/screen/device" )
@Api(value = "iecgscreendevice", tags = "大屏设备中心管理")
public class IecgScreenDeviceController {

    private final IecgScreenDeviceService iecgScreenDeviceService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param iecgScreenDevice 设备中心
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getIecgScreenDevicePage(Page page, IecgScreenDevice iecgScreenDevice) {
        return R.ok(iecgScreenDeviceService.page(page, Wrappers.query(iecgScreenDevice)));
    }


    /**
     * 通过id查询设备中心
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(iecgScreenDeviceService.getById(id));
    }

    /**
     * 新增设备中心
     * @param iecgScreenDevice 设备中心
     * @return R
     */
    @ApiOperation(value = "新增设备中心", notes = "新增设备中心")
    @SysLog("新增设备中心" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('screen_device_add')" )
    public R save(@RequestBody IecgScreenDevice iecgScreenDevice) {
        return R.ok(iecgScreenDeviceService.save(iecgScreenDevice));
    }

    /**
     * 修改设备中心
     * @param iecgScreenDevice 设备中心
     * @return R
     */
    @ApiOperation(value = "修改设备中心", notes = "修改设备中心")
    @SysLog("修改设备中心" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('screen_device_edit')" )
    public R updateById(@RequestBody IecgScreenDevice iecgScreenDevice) {
        return R.ok(iecgScreenDeviceService.updateById(iecgScreenDevice));
    }

    /**
     * 通过id删除设备中心
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除设备中心", notes = "通过id删除设备中心")
    @SysLog("通过id删除设备中心" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('screen_device_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(iecgScreenDeviceService.removeById(id));
    }


	/**
	 * 通过id查询设备中心
	 * @param
	 * @return R
	 */
	@ApiOperation(value = "预警大屏查询设备中心", notes = "预警大屏查询设备中心")
	@GetMapping("/first" )
	public R getWithScreen() {
		return R.ok(iecgScreenDeviceService.getOne(Wrappers.<IecgScreenDevice>query()
				.lambda().last("limit 1")));
	}
}
